/** @jsxImportSource @emotion/react */
import * as React from "react";
import {OriginalViewProps, } from "../../common/base";
import {EntranceSetup, config设备概况, config观测数据,} from "./orcBase";
import {createItem, } from "../../common/eHelper";
import {useRecordList} from "../../hook/useRecordList";
import {setupItemAreaRoute} from "./orcIspConfig";
import {EditStorageContext} from "../../StorageContext";
import {Text, useTheme} from "customize-easy-ui-component";
import {ItemInstrumentTable} from "../../common/Instrument";
import {FrontCover } from "../../mobilecr/editorIN";
import {SiteConditionSund,} from "../../elevator/sundryDj/editor";
import {GenCode} from "../../common/GenCode";
import {ActionMapItem} from "../../common/ActionMapItem";
import {config记录} from "./FormatOriginal";
import {config检验复检表, RecheckEditor} from "../../common/editor";
import {DeviceSurveyD} from "../../crane/editor";
import {WitnessSimple} from "../../elevator/stest/editor";
import {MeasureJudgmentMem} from "../../amusement/editor";
import {ConclusionHydlic} from "../../lift/hydlicDj/editor";
import {ObservationMeasureTourIn} from "../tour/editMeasu";
import {config绝缘阻, config行驶速度, config路线坡度, config踏板力, config驻车制力} from "../tour/orcBase";
import {MeasureCritMem} from "../../hook/useMeasure";
import {BrakingDistance} from "../tour/BrakingDistance";
import {tItems现场} from "../tour/Regular.O-1";


//模型参数 "pr":"*",  "r":3,"s":1, "big":"", "ts":[13,14] ,"vx":1
//这个报告特例 nos：没有区分开啊。 【看着像】自采分项目的但是全部算成独立的结论。 生成假定是nos连续的编码，然后【手动进一步做修改】nos:
const defFrameM={
    'CmnTowerCrane': `{ "mg":2, "dcl":"","cl":"",
           "sk":[ {"no":"2.6(1)", "r":0, "bs":[7],"ss":[2] },0,
            {"no":"2.7(1)", "r":0, "ss":[5] }, 0,0 , 0,0
     ] }`,
};
/*特殊nos编码的例子，1.2(1)本应该是自采分项目，可实际每个结论都独立的！
'CmnTowerCrane': `{ "mg":2, "dcl":"","cl":"",
           "sk":[ {"no":"1.1(1)", "r":0, "bs":[9],"ss":[4] }, 0,0,0, {"no":"1.2(1)", "r":0, "ss":[5] }, 0,0,0,0
     ] }`
'CmnTowerCrane': `{ "mg":2, "dcl":"","cl":"",
           "sk":[ {"no":"2.1", "r":0, "bs":[7],"ss":[1] }, {"no":"2.2(1)", "r":0, "ss":[6] }, 0,0,0,0 ,0
     ] }`,
* */
const inNode_A1=<>
    <hr/>
    b.连续20m路段坡度(用水平仪测量时填写在下列表格中） &gt;
</>;
const memolist=['驾驶人员应持有效作业人员证。', ];
const recordPrintList =[
    createItem('Entrance', <EntranceSetup/>),
    createItem('FrontCover', <FrontCover/>),
    createItem('Instrument', <ItemInstrumentTable label={'一、主要检验仪器设备性能检查'} />),
    createItem('Survey', <DeviceSurveyD config={config设备概况} label={'二、设备概况'}/>),
    createItem('Item', null),
    createItem('ReCheck', <RecheckEditor config={config检验复检表} label={'四、检验不符合项目记录及复检结果'} setup={setupItemAreaRoute}/>),
    createItem('Conclusion', <ConclusionHydlic  label={'五、综合结论'}/>),
    createItem('Witness', <WitnessSimple nowit label={'六、备注'} titles={[null,'六、备注']} memolist={memolist}
                                         children={[null,
                             <React.Fragment key={12}>注：特殊情况，应在备注中说明检验人员所负责检验的项目编号。</React.Fragment>
                         ]}/>),
    createItem('Measure', <MeasureJudgmentMem config={config观测数据}  label={'七、观测数据及测量结果记录'}>
            </MeasureJudgmentMem>),
    createItem('MeasureA1', <ObservationMeasureTourIn config={config路线坡度} label={'附录A1:行驶路线坡度检测'} inIdx={2} inNode={inNode_A1}/>),
    createItem('MeasureA2', <MeasureCritMem config={config行驶速度} label={'附录A2:最大行驶速度检测'}/>),
    createItem('MeasureA3', <MeasureCritMem config={config驻车制力} label={'附录A3:驻车制动操作力检测'}/>),
        //createItem('Measure', <MeasureCritMem config={config观测数据}  label={'八、观测数据及测量结果记录'}> </MeasureCritMem>),
    createItem('BrakingDistance', <BrakingDistance label={'附录A4:行车制动距离测量'}/>),
    createItem('MeasureA5', <MeasureCritMem config={config踏板力} label={'附录A5:行车制动踏板力检测'}/>),
    createItem('MeasureA6', <MeasureCritMem config={config绝缘阻} label={'附录A6:绝缘电阻检测'}/>),
    createItem('SiteCondition', <SiteConditionSund config={tItems现场} label={'附录B：现场检测条件确认'}/>),
];
if(process.env.REACT_APP_TEST==='true')  recordPrintList.splice(0,0,createItem('GenCode', <GenCode type='CmnTowerCrane' frameMod={defFrameM}/>));


export const OriginalView=
  React.forwardRef((
    { action,  verId, repId='', rep,}
    :OriginalViewProps, ref
  ) => {
    const context =React.useContext(EditStorageContext);
    if(context == null)    throw new Error("EditStorageContext没有提供");
    const {storage, } =context;
    const theme = useTheme();
    const recordPrintListNow =React.useMemo(() => {
      let routeAreas=[] as any[];
      const impressionismAs =setupItemAreaRoute({rep, orc:storage, theme});
      let extendTags =Reflect.ownKeys(impressionismAs) as string[];
      const oldItCount=recordPrintList.length;
      let prevpos=0;
      for(let p=0; p<oldItCount; p++){
        if(extendTags.indexOf(recordPrintList[p].itemArea)>=0){     //需要展开 扩充的标签
            routeAreas=routeAreas.concat(recordPrintList.slice(prevpos,p));
            const itemConfigs= impressionismAs?.[recordPrintList[p].itemArea];
            let seq = 0;
            let moreItems = [] as any;
            itemConfigs.forEach((area, x) => {
              seq += 1;
              const rowHead =<ActionMapItem key={seq} alone={false} editAreasConf={itemConfigs}
                                                    index={x} sureD editIts={config记录} />;
              moreItems.push(createItem(area.tag, rowHead));
            });
            routeAreas=routeAreas.concat(moreItems);
            prevpos=p+1;
        }
      }
      routeAreas=routeAreas.concat(recordPrintList.slice(prevpos));
      return routeAreas;
    }, [verId, repId,rep, storage?._Oitems, theme]);

    const {list}=useRecordList(ref,rep,recordPrintListNow,action,verId);
    return <React.Fragment>
      {list}
        {/*      <Button  intent="primary"
                   onPress={(e) => { handleSubmit!();
                   }}
          >送打印转换器
          </Button>*/}
    </React.Fragment>;
  } );
